﻿Namespace Web
    Partial Public Class LLibreCaixa

#Region "Dates"

        Public Property HoraObertura As TimeSpan
            Get
                Return DataHoraObertura.TimeOfDay
            End Get
            Set(value As TimeSpan)
                DataHoraObertura = DataHoraObertura.Date + value
                RaisePropertyChanged("HoraObertura")
                RaisePropertyChanged("strHoraObertura")
            End Set
        End Property

        Public Property strHoraObertura As String
            Get
                Return Right("00" & HoraObertura.Hours, 2) & ":" & Right("00" & HoraObertura.Minutes, 2) '& ":" & Right("00" & DataHora.Seconds, 2)
            End Get
            Set(value As String)
                Try
                    HoraObertura = TimeSpan.Parse(value)
                    RaisePropertyChanged("strHoraObertura")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property

        Public Property HoraTancament As TimeSpan?
            Get
                If DataHoraTancament.HasValue Then
                    Return DataHoraTancament.Value.TimeOfDay
                Else
                    Return Nothing
                End If
            End Get
            Set(value As TimeSpan?)
                If DataHoraTancament.HasValue Then
                    DataHoraTancament = DataHoraTancament.Value.Date + value
                Else
                    DataHoraTancament = Now.Date + value
                End If

                RaisePropertyChanged("HoraTancament")
                RaisePropertyChanged("strHoraTancament")
            End Set
        End Property

        Public Property strHoraTancament As String
            Get
                If HoraTancament.HasValue Then
                    Return Right("00" & HoraTancament.Value.Hours, 2) & ":" & Right("00" & HoraTancament.Value.Minutes, 2) '& ":" & Right("00" & DataHora.Seconds, 2)
                Else
                    Return ""
                End If
            End Get
            Set(value As String)
                Try
                    If value = "" Then
                        HoraTancament = Nothing
                    Else
                        HoraTancament = TimeSpan.Parse(value)
                    End If
                    RaisePropertyChanged("strHoraTancament")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property

        Public Property strData As String
            Get
                Return Right("00" & Data.Day, 2) & "/" & Right("00" & Data.Month, 2) & "/" & Right("0000" & Data.Year, 4)
            End Get
            Set(value As String)
                Try
                    Data = Date.Parse(value)
                    RaisePropertyChanged("strData")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property


        Private Sub OnDataHoraOberturaChanged()
            RaisePropertyChanged("strHoraObertura")
            RaisePropertyChanged("HoraObertura")
        End Sub

        Private Sub OnDataHoraTancamentChanged()
            RaisePropertyChanged("strHoraTancament")
            RaisePropertyChanged("HoraTancament")
            RaisePropertyChanged("EsTancat")
        End Sub

        Private Sub OnDataChanged()
            RaisePropertyChanged("strData")
        End Sub
#End Region

#Region "Camps Numerics"

        Public Property strCaixaInicial As String
            Get
                Return Format(CaixaInicial, "0.00").Replace(".", ",")
            End Get
            Set(value As String)
                value = value.Replace(".", ",")
                Try
                    CaixaInicial = Double.Parse(value)
                    RaisePropertyChanged("strCaixaInicial")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property

        Public Property strCaixaFinal As String
            Get
                If CaixaFinal.HasValue Then
                    Return Format(CaixaFinal, "0.00").Replace(".", ",")
                Else
                    Return ""
                End If
            End Get
            Set(value As String)
                value = value.Replace(".", ",")
                Try
                    If value = "" Then
                        CaixaFinal = Nothing
                    Else
                        CaixaFinal = Double.Parse(value)
                    End If
                    RaisePropertyChanged("strCaixaFinal")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property

        Public ReadOnly Property strTotalCash As String
            Get
                If TotalCash.HasValue Then
                    Return Format(TotalCash, "0.00").Replace(".", ",")
                Else
                    Return ""
                End If
            End Get
        End Property

        Public ReadOnly Property strTotalTargeta As String
            Get
                If TotalTargeta.HasValue Then
                    Return Format(TotalTargeta, "0.00").Replace(".", ",")
                Else
                    Return ""
                End If
            End Get
        End Property

        Public Property strSobre As String
            Get
                If Sobre.HasValue Then
                    Return Format(Sobre, "0.00").Replace(".", ",")
                Else
                    Return ""
                End If
            End Get
            Set(value As String)
                value = value.Replace(".", ",")
                Try
                    If value = "" Then
                        Sobre = Nothing
                    Else
                        Sobre = Double.Parse(value)
                    End If
                    RaisePropertyChanged("strSobre")
                Catch ex As Exception
                    Throw New FormatException()
                End Try
            End Set
        End Property


        Private Sub OnCaixaInicialChanged()
            RaisePropertyChanged("strCaixaInicial")
            RaisePropertyChanged("TotalCalculat")
            RaisePropertyChanged("strTotalCalculat")
            RaisePropertyChanged("Diferencial")
            RaisePropertyChanged("strDiferencial")
        End Sub

        Private Sub OnCaixaFinalChanged()
            RaisePropertyChanged("strCaixaFinal")
            RaisePropertyChanged("Diferencial")
            RaisePropertyChanged("strDiferencial")
        End Sub

        Private Sub OnTotalTargetaChanged()
            RaisePropertyChanged("strTotalTargeta")
        End Sub

        Private Sub OnTotalCashChanged()
            RaisePropertyChanged("strTotalCash")
            RaisePropertyChanged("TotalCalculat")
            RaisePropertyChanged("strTotalCalculat")
            RaisePropertyChanged("Diferencial")
            RaisePropertyChanged("strDiferencial")
        End Sub

        Private Sub OnSobreChanged()
            RaisePropertyChanged("strSobre")
            RaisePropertyChanged("TotalCalculat")
            RaisePropertyChanged("strTotalCalculat")
            RaisePropertyChanged("Diferencial")
            RaisePropertyChanged("strDiferencial")
        End Sub
#End Region

#Region "Camps Calculats"
        Public Sub ActualitzarCampsCalculats()
            RaisePropertyChanged("TotalCash")
            RaisePropertyChanged("TotalTargeta")
            RaisePropertyChanged("TotalCalculat")
            RaisePropertyChanged("strTotalCalculat")
            RaisePropertyChanged("Diferencial")
            RaisePropertyChanged("strDiferencial")
        End Sub

        Public ReadOnly Property strTotalCalculat As String
            Get
                Return Format(TotalCalculat, "0.00").Replace(".", ",")
            End Get
        End Property

        Public ReadOnly Property strDiferencial As String
            Get
                Return Format(Diferencial, "0.00").Replace(".", ",")
            End Get
        End Property
#End Region

#Region "Estat Hostal"
        Public Property EstatRecepcioIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatRecepcioInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatRecepcioInici = value.Id
                Else
                    Me.EstatRecepcioInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatBanyIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatBanyInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatBanyInici = value.Id
                Else
                    Me.EstatBanyInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatCuinaIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatCuinaInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatCuinaInici = value.Id
                Else
                    Me.EstatCuinaInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatSalaIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatSalaInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatSalaInici = value.Id
                Else
                    Me.EstatSalaInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatPassadisIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatPassadisInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatPassadisInici = value.Id
                Else
                    Me.EstatPassadisInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatTerrassaIniciItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatTerrassaInici, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatTerrassaInici = value.Id
                Else
                    Me.EstatTerrassaInici = Nothing
                End If
            End Set
        End Property

        Public Property EstatRecepcioFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatRecepcioFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatRecepcioFinal = value.Id
                Else
                    Me.EstatRecepcioFinal = Nothing
                End If
            End Set
        End Property

        Public Property EstatBanyFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatBanyFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatBanyFinal = value.Id
                Else
                    Me.EstatBanyFinal = Nothing
                End If
            End Set
        End Property

        Public Property EstatCuinaFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatCuinaFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatCuinaFinal = value.Id
                Else
                    Me.EstatCuinaFinal = Nothing
                End If
            End Set
        End Property

        Public Property EstatSalaFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatSalaFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatSalaFinal = value.Id
                Else
                    Me.EstatSalaFinal = Nothing
                End If
            End Set
        End Property

        Public Property EstatPassadisFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatPassadisFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatPassadisFinal = value.Id
                Else
                    Me.EstatPassadisFinal = Nothing
                End If
            End Set
        End Property

        Public Property EstatTerrassaFinalItem() As OpcioCombo
            Get
                Return OpcionsComboEstatHostal.GetOpcions.Where(Function(f) f.Id = If(EstatTerrassaFinal, EnumEstatHostal.Indefinit)).FirstOrDefault()
            End Get
            Set(ByVal value As OpcioCombo)
                If value IsNot Nothing AndAlso value.Id <> EnumEstatHostal.Indefinit Then
                    Me.EstatTerrassaFinal = value.Id
                Else
                    Me.EstatTerrassaFinal = Nothing
                End If
            End Set
        End Property

        Private Sub OnEstatBanyFinalChanged()
            RaisePropertyChanged("EstatBanyFinalItem")
        End Sub

        Private Sub OnEstatBanyIniciChanged()
            RaisePropertyChanged("EstatBanyIniciItem")
        End Sub

        Private Sub OnEstatCuinaFinalChanged()
            RaisePropertyChanged("EstatCuinaFinalItem")
        End Sub

        Private Sub OnEstatCuinaIniciChanged()
            RaisePropertyChanged("EstatCuinaIniciItem")
        End Sub

        Private Sub OnEstatPassadisFinalChanged()
            RaisePropertyChanged("EstatPassadisFinalItem")
        End Sub

        Private Sub OnEstatPassadisIniciChanged()
            RaisePropertyChanged("EstatPassadisIniciItem")
        End Sub

        Private Sub OnEstatRecepcioFinalChanged()
            RaisePropertyChanged("EstatRecepcioFinalItem")
        End Sub

        Private Sub OnEstatRecepcioIniciChanged()
            RaisePropertyChanged("EstatRecepcioIniciItem")
        End Sub

        Private Sub OnEstatSalaFinalChanged()
            RaisePropertyChanged("EstatSalaFinalItem")
        End Sub

        Private Sub OnEstatSalaIniciChanged()
            RaisePropertyChanged("EstatSalaIniciItem")
        End Sub

        Private Sub OnEstatTerrassaFinalChanged()
            RaisePropertyChanged("EstatTerrassaFinalItem")
        End Sub

        Private Sub OnEstatTerrassaIniciChanged()
            RaisePropertyChanged("EstatTerrassaIniciItem")
        End Sub

#End Region


    End Class
End Namespace
